﻿using CanalService.EFCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CanalService.EFCore
{
    public static class EFCoreDBContextServiceCollectionExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="services"></param>
        /// <param name="setupAction"></param>
        /// <returns></returns>
        public static IServiceCollection AddEFCoreDBContext<T>(this IServiceCollection services, Action<EFCoreDBContextOptions> setupAction) where T : EFCoreDBContext
        {
            if (services == null)
            { throw new ArgumentNullException(nameof(services)); }
            if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction)); }
            
            services.Configure(setupAction);
            services.AddScoped<T>();
            services.AddScoped<ProjectEFCoreContext>();
            return services;
        }

    }
}
